import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    beforeEnter:(to,from,next)=>{
      // console.log(to)
      // console.log(from)
      // console.log(next)
      // 从 sessionStorage 中获取到 保存的 token 值
      const tokenStr = window.sessionStorage.getItem('token')
      // 没有token，强制跳转到登录页
      if (!tokenStr) {return next('/login');}
      next()
    },
    component: Home,
    children:[
      {
        path: 'infot',  // 注意点：路径前面不要带/，否则无法跳转，在这里吃过亏
        name: 'infot',
        components: {   // 注意参数名带s
          table: () => import('../views/Infot.vue')  // 这里的table跟首页的router-view标签的name一致，才会在首页的路由视图进行跳转，看3.2
        }
      },
      {
        path: 'infolist', //内容列表
        name: 'infolist',
        components: {  
          table: () => import('../views/Infolist.vue') 
        }
      },
      {
        path: 'diqu', //地区列表
        name: 'diqu',
        components: {  
          table: () => import('../views/Diqu.vue') 
        }
      },
      {
        path: 'jiaolian', //教练列表
        name: 'jiaolian',
        components: {  
          table: () => import('../views/Jiaolian.vue') 
        }
      },
      {
        path: 'changdi', //场地列表
        name: 'changdi',
        components: {  
          table: () => import('../views/Changdi.vue') 
        }
      },
      {
        path: 'taocan', //学车套餐列表
        name: 'taocan',
        components: {  
          table: () => import('../views/Taocan.vue') 
        }
      },
      {
        path: 'userlist', //用户列表
        name: 'userlist',
        components: {  
          table: () => import('../views/Userlist.vue') 
        }
      },
      {
        path: 'usert', //用户组
        name: 'usert',
        components: {  
          table: () => import('../views/Usert.vue') 
        }
      },
      {
        path: 'quanxian', //权限列表
        name: 'quanxian',
        components: {  
          table: () => import('../views/Quanxian.vue') 
        }
      },
      {
        path: 'quanxian2', //权限列表
        name: 'quanxian2',
        components: {  
          table: () => import('../views/Quanxian2.vue') 
        }
      },
      {
        path: 'web', //站点设置 
        name: 'web',
        components: {  
          table: () => import('../views/Web.vue') 
        }
      },
      {
        path: 'adminlist', //管理员列表
        name: 'adminlist',
        components: {  
          table: () => import('../views/Adminlist.vue') 
        }
      },
      {
        path: 'admint', //管理组列表
        name: 'admint',
        components: {  
          table: () => import('../views/Admint.vue') 
        }
      },
      {
        path: 'caozuolist', //操作记录
        name: 'caozuolist',
        components: {  
          table: () => import('../views/Caozuolist.vue') 
        }
      },
      {
        path: 'kaifa', //开发设置
        name: 'kaifa',
        components: {  
          table: () => import('../views/Kaifa.vue') 
        }
      },
      {
        path: 'daohang', //导航
        name: 'daohang',
        components: {  
          table: () => import('../views/Daohang.vue') 
        }
      },
      {
        path: 'banner', //幻灯片分类
        name: 'banner',
        components: {  
          table: () => import('../views/Banner.vue') 
        }
      },
      {
        path: 'banner_list', //幻灯片列表
        name: 'banner_list',
        components: {  
          table: () => import('../views/Banner_list.vue') 
        }
      },
      {
        path: 'diy', //自定义参数
        name: 'diy',
        components: {  
          table: () => import('../views/Diy.vue') 
        }
      },
      {
        path: 'zidian', //字典分类
        name: 'zidian',
        components: {  
          table: () => import('../views/Zidian.vue') 
        }
      },
      {
        path: 'zidian_list', //字典列表
        name: 'zidian_list',
        components: {  
          table: () => import('../views/Zidian_list.vue') 
        }
      },
      {
        path: 'setsql', //数据库
        name: 'setsql',
        components: {  
          table: () => import('../views/Setsql.vue') 
        }
      },
      {
        path: 'alipay', //支付宝设置
        name: 'alipay',
        components: {  
          table: () => import('../views/Alipay.vue') 
        }
      },
      {
        path: 'weixin', //微信设置
        name: 'weixin',
        components: {  
          table: () => import('../views/Weixin.vue') 
        }
      },
      {
        path: 'sms', //短信设置
        name: 'sms',
        components: {  
          table: () => import('../views/Sms.vue') 
        }
      },
      {
        path: 'haibao', //海报
        name: 'haibao',
        components: {  
          table: () => import('../views/Haibao.vue') 
        }
      },
      {
        path: 'fenxiao', //分销
        name: 'fenxiao',
        components: {  
          table: () => import('../views/Fenxiao.vue') 
        }
      },
      {
        path: 'fenxiao2', //提现
        name: 'fenxiao2',
        components: {  
          table: () => import('../views/Fenxiao2.vue') 
        }
      },
      {
        path: 'baidu', //百度
        name: 'baidu',
        components: {  
          table: () => import('../views/Baidu.vue') 
        }
      },
      {
        path: 'douyin', //抖音
        name: 'douyin',
        components: {  
          table: () => import('../views/Douyin.vue') 
        }
      }, 
      {
        path: 'qiniu', //七牛
        name: 'qiniu',
        components: {  
          table: () => import('../views/Qiniu.vue') 
        }
      },
      {
        path: 'qita', //其他
        name: 'qita',
        components: {  
          table: () => import('../views/Qita.vue') 
        }
      },


    ]
  },
  {
    path: '/login',
    name: 'Login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  }
  
]

const router = createRouter({
  history: createWebHashHistory(),
  // mode: "hash", 
  routes
})

export default router
